home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / uplevel.test < prev    next >
Text File  |  1993-07-17  |  4KB  |  124 lines

  1. # Commands covered:  uplevel
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/uplevel.test,v 1.11 93/07/17 14:38:22 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. proc a {x y} {
  32.     newset z [expr $x+$y]
  33.     return $z
  34. }
  35. proc newset {name value} {
  36.     uplevel set $name $value
  37.     uplevel 1 {uplevel 1 {set xyz 22}}
  38. }
  39.  
  40. test uplevel-1.1 {simple operation} {
  41.     set xyz 0
  42.     a 22 33
  43. } 55
  44. test uplevel-1.2 {command is another uplevel command} {
  45.     set xyz 0
  46.     a 22 33
  47.     set xyz
  48. } 22
  49.  
  50. proc a1 {} {
  51.     b1
  52.     global a a1
  53.     set a $x
  54.     set a1 $y
  55. }
  56. proc b1 {} {
  57.     c1
  58.     global b b1
  59.     set b $x
  60.     set b1 $y
  61. }
  62. proc c1 {} {
  63.     uplevel 1 set x 111
  64.     uplevel #2 set y 222
  65.     uplevel 2 set x 333
  66.     uplevel #1 set y 444
  67.     uplevel 3 set x 555
  68.     uplevel #0 set y 666
  69. }
  70. a1
  71. test uplevel-2.1 {relative and absolute uplevel} {set a} 333
  72. test uplevel-2.2 {relative and absolute uplevel} {set a1} 444
  73. test uplevel-2.3 {relative and absolute uplevel} {set b} 111
  74. test uplevel-2.4 {relative and absolute uplevel} {set b1} 222
  75. test uplevel-2.5 {relative and absolute uplevel} {set x} 555
  76. test uplevel-2.6 {relative and absolute uplevel} {set y} 666
  77.  
  78. test uplevel-3.1 {uplevel to same level} {
  79.     set x 33
  80.     uplevel #0 set x 44
  81.     set x
  82. } 44
  83. test uplevel-3.2 {uplevel to same level} {
  84.     set x 33
  85.     uplevel 0 set x
  86. } 33
  87. test uplevel-3.3 {uplevel to same level} {
  88.     set y xxx
  89.     proc a1 {} {set y 55; uplevel 0 set y 66; return $y}
  90.     a1
  91. } 66
  92. test uplevel-3.4 {uplevel to same level} {
  93.     set y zzz
  94.     proc a1 {} {set y 55; uplevel #1 set y}
  95.     a1
  96. } 55
  97.  
  98. test uplevel-4.1 {error: non-existent level} {
  99.     list [catch c1 msg] $msg
  100. } {1 {bad level "#2"}}
  101. test uplevel-4.2 {error: non-existent level} {
  102.     proc c2 {} {uplevel 3 {set a b}}
  103.     list [catch c2 msg] $msg
  104. } {1 {bad level "3"}}
  105. test uplevel-4.3 {error: not enough args} {
  106.     list [catch uplevel msg] $msg
  107. } {1 {wrong # args: should be "uplevel ?level? command ?arg ...?"}}
  108. test uplevel-4.4 {error: not enough args} {
  109.     proc upBug {} {uplevel 1}
  110.     list [catch upBug msg] $msg
  111. } {1 {wrong # args: should be "uplevel ?level? command ?arg ...?"}}
  112.  
  113. proc a2 {} {
  114.     uplevel a3
  115. }
  116. proc a3 {} {
  117.     global x y
  118.     set x [info level]
  119.     set y [info level 1]
  120. }
  121. a2
  122. test uplevel-5.1 {info level} {set x} 1
  123. test uplevel-5.2 {info level} {set y} a3
  124.